<html>
<head>
<title>ListUtilities.java</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
.ln { color: rgb(0,0,0); font-weight: normal; font-style: normal; }
.s0 { color: rgb(0,0,128); font-weight: bold; }
.s1 { }
</style>
</head>
<BODY BGCOLOR="#ffffff">
<TABLE CELLSPACING=0 CELLPADDING=5 COLS=1 WIDTH="100%" BGCOLOR="#C0C0C0" >
<TR><TD><CENTER>
<FONT FACE="Arial, Helvetica" COLOR="#000000">
ListUtilities.java</FONT>
</center></TD></TR></TABLE>
<pre>

<span class="s0">package </span><span class="s1">com.example.lista_zakupow.database.utils; 
 
</span><span class="s0">import </span><span class="s1">android.database.Cursor; 
</span><span class="s0">import </span><span class="s1">com.example.lista_zakupow.database.utils.tables_headers.ListaZakupowTableHeaders; 
</span><span class="s0">import </span><span class="s1">com.example.lista_zakupow.database.utils.tables_headers.ProduktyTableHeaders; 
</span><span class="s0">import </span><span class="s1">com.example.lista_zakupow.zakupy.Jednostki; 
</span><span class="s0">import </span><span class="s1">com.example.lista_zakupow.zakupy.ListaZakupow; 
</span><span class="s0">import </span><span class="s1">com.example.lista_zakupow.zakupy.Produkt; 
 
</span><span class="s0">import </span><span class="s1">java.util.ArrayList; 
</span><span class="s0">import </span><span class="s1">java.util.List; 
 
</span><span class="s0">public class </span><span class="s1">ListUtilities { 
    </span><span class="s0">public static </span><span class="s1">List&lt;ListaZakupow&gt; getAllListaZakupowFromCursorObiect(Cursor c) { 
        List&lt;ListaZakupow&gt; listArray = </span><span class="s0">new </span><span class="s1">ArrayList&lt;ListaZakupow&gt;(); 
        c.moveToFirst(); 
        </span><span class="s0">while </span><span class="s1">(c.isAfterLast() == </span><span class="s0">false</span><span class="s1">) { 
            ListaZakupow listaZakupow = createListBy(c); 
            listArray.add(listaZakupow); 
            c.moveToNext(); 
        } 
        </span><span class="s0">return </span><span class="s1">listArray; 
    } 
 
    </span><span class="s0">public static </span><span class="s1">List&lt;Produkt&gt; getAllProductsFromCursorObiect(Cursor c) { 
        List&lt;Produkt&gt; produktsList = </span><span class="s0">new </span><span class="s1">ArrayList&lt;Produkt&gt;(); 
        c.moveToFirst(); 
        </span><span class="s0">while </span><span class="s1">(c.isAfterLast() == </span><span class="s0">false</span><span class="s1">) { 
            Produkt produkt = createProductBy(c); 
            produktsList.add(produkt); 
            c.moveToNext(); 
        } 
        </span><span class="s0">return </span><span class="s1">produktsList; 
    } 
 
    </span><span class="s0">private static </span><span class="s1">ListaZakupow createListBy(Cursor c) { 
        </span><span class="s0">int </span><span class="s1">listId = c.getInt(c.getColumnIndex(ListaZakupowTableHeaders.LIST_ID)); 
        String listName = c.getString(c.getColumnIndex(ListaZakupowTableHeaders.LIST_NAME)); 
 
        </span><span class="s0">return new </span><span class="s1">ListaZakupow(listId, listName); 
    } 
 
    </span><span class="s0">private static </span><span class="s1">Produkt createProductBy(Cursor c) { 
        </span><span class="s0">int </span><span class="s1">productId = c.getInt(c.getColumnIndex(ProduktyTableHeaders.PRODUCT_ID)); 
        String productName = c.getString(c.getColumnIndex(ProduktyTableHeaders.PRODUCT_NAME)); 
        </span><span class="s0">int </span><span class="s1">howMany = c.getInt(c.getColumnIndex(ProduktyTableHeaders.HOW_MANY)); 
        String unit = c.getString(c.getColumnIndex(ProduktyTableHeaders.UNIT)); 
        Jednostki jednostka = Jednostki.valueOf(unit); 
 
        </span><span class="s0">return new </span><span class="s1">Produkt(productId, productName, howMany, jednostka); 
    } 
} 
</span></pre>
</body>
</html>